﻿using biaoqian.CSwnjian;
using Kingdee.BOS.WebApi.DataEntities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FastReport;
using System.Windows.Forms;
using NPOI.POIFS.Crypt.Dsig;
using System.IO;
using Infragistics.Documents.Reports.Report;
using Report = FastReport.Report;
using Org.BouncyCastle.Bcpg;

namespace biaoqian
{
    public partial class Cangku : Form
    {
        public Cangku()
        {
            InitializeComponent();
        }
        Class1 one = new Class1();
        CHK HK = new CHK();
        CSwnjian.Cangku ck = new CSwnjian.Cangku();

        private void button1_Click(object sender, EventArgs e)
        {
            var kehu = this.comboBox1.Text;
            var wulia = this.comboBox2.Text;
            var hang = this.textBox1.Text;
            var DAnhao = this.comboBox3.Text;
            DataTable dt = ck.Jins(kehu, hang, wulia, DAnhao);
            comboBox2.Items.Clear();
            comboBox3.Items.Clear();
            DataTable DAnhaoT = one.DAtaijs();
            DAnhaoT.Columns.Add("ding", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                var jins = dr["encoding"].ToString();
                DataRow[] B = DAnhaoT.Select("ding='" + jins + "'");
                
                if (B.Length == 0)
                {
                    DataRow data = DAnhaoT.NewRow();
                    data["ding"] = jins;
                    DAnhaoT.Rows.Add(data);
                    comboBox3.Items.Add(jins);
                }
                comboBox2.Items.Add(dr["FMaterial"].ToString());
            }
            dataGridView1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var kehu = this.comboBox1.Text;
            var wulia = this.comboBox2.Text;
            var hang = this.textBox1.Text;
            var DAnhao = this.comboBox3.Text;
            var QTY = this.textBox2.Text;
            DataTable dt = ck.Jins(kehu, hang, wulia, DAnhao);
            DataRow row = dt.Rows[0];
            if (this.textBox2.Text == "")
            {
                MessageBox.Show("请输入QTY数量！");
                return;
            }
            else
            {
                Report report = new Report();
                var Biao = "";
                DataSet ds = new DataSet();
                if (row["Shipping"].ToString() == "和硕联合科技股份有限公司")
                {
                    Biao = "Fastreport\\Heshuo1.frx";
                    DataTable T = HK.HEsuo(dt, QTY);
                    ds.Tables.Add(T);
                    T.TableName = "Table1";
                }
                if (row["Shipping"].ToString() == "立讯电子科技（昆山）有限公司")
                {
                    Biao = "Fastreport\\Lixun.frx";
                    DataTable T = HK.Lixun(dt, QTY);
                    ds.Tables.Add(T);
                    T.TableName = "Table1";
                }
                if (row["Shipping"].ToString() == "昆山美普森包装有限公司")
                {
                    Biao = "Fastreport\\Meibus.frx";
                    DataTable T = HK.MPS(dt, QTY);
                    ds.Tables.Add(T);
                    T.TableName = "Table1";
                }
                if (row["Shipping"].ToString() == "四海电子（昆山）有限公司（兰多）")
                {
                    Biao = "Fastreport\\SIhai_1.frx";
                    DataTable T = HK.SiHai(dt, QTY);
                    ds.Tables.Add(T);
                    T.TableName = "Table1";
                }
                //string baseDirectory1 = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Biao);
                report.Load(filename);

                report.RegisterData(ds);//绑定数据源
                DataBand data = report.Report.FindObject("Data1") as DataBand;
                data.DataSource = report.Report.GetDataSource("Table1");
                report.PrintSettings.Copies = 1;
                /*}
                else
                {
                    var sdk = int.Parse(row["quantity"].ToString());
                    report.PrintSettings.Copies = 1;
                    var A1 = row["Shipping"].ToString();
                    var A2 = row["FMaterial"].ToString();
                    var A3 = row["encoding"].ToString();
                    report.SetParameterValue("Kehu", A1);
                    report.SetParameterValue("Wuliao", A2);
                    report.SetParameterValue("Danha", A3);
                }*/
                report.Prepare();
                report.ShowPrepared();
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count > 0)
            {
                this.textBox1.Text = (this.dataGridView1.SelectedRows[0].Index + 1).ToString();
            }
        }
    }
}
